package com.boot.communal.response;

import lombok.Data;

import java.util.Date;

/**
 * 封装请求响应的数据信息并将处理结果封装返回
 *
 * @param <T>
 * @author 【zhouJie】
 */
@Data
public class ResponseServer<T> {

    private int code;
    private String message;
    private boolean isSuccess;
    private T data;
    private Date time;

    public ResponseServer(int code, String message, boolean isSuccess, Date time) {
        this.code = code;
        this.message = message;
        this.isSuccess = isSuccess;
        this.time = time;
    }

    public ResponseServer(int code, String message, boolean isSuccess, T data, Date time) {
        this.code = code;
        this.message = message;
        this.isSuccess = isSuccess;
        this.data = data;
        this.time = time;
    }

    public static ResponseServer success() {
        return new ResponseServer(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), ResponseCode.SUCCESS.isSuccess(), ResponseCode.SUCCESS.getTime());
    }

    public static ResponseServer success(String message) {
        return new ResponseServer(ResponseCode.SUCCESS.getCode(), message, ResponseCode.SUCCESS.isSuccess(), ResponseCode.SUCCESS.getTime());
    }

    public static <T> ResponseServer success(T data) {
        return new ResponseServer(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), ResponseCode.SUCCESS.isSuccess(), data, ResponseCode.SUCCESS.getTime());
    }

    public static <T> ResponseServer success(String message, T data) {
        return new ResponseServer(ResponseCode.SUCCESS.getCode(), message, ResponseCode.SUCCESS.isSuccess(), data, ResponseCode.SUCCESS.getTime());
    }

    public static ResponseServer error(String message) {
        return new ResponseServer(ResponseCode.ERROR.getCode(), message, ResponseCode.ERROR.isSuccess(), ResponseCode.ERROR.getTime());
    }

    public static ResponseServer authorization_expired(String message) {
        return new ResponseServer(ResponseCode.Authorization_Expired.getCode(), message, ResponseCode.Authorization_Expired.isSuccess(), ResponseCode.Authorization_Expired.getTime());
    }

    public static ResponseServer no_authority(String message) {
        return new ResponseServer(ResponseCode.No_Authority.getCode(), message, ResponseCode.No_Authority.isSuccess(), ResponseCode.No_Authority.getTime());
    }

    public static ResponseServer no_authorization(String message) {
        return new ResponseServer(ResponseCode.No_Authorization.getCode(), message, ResponseCode.No_Authorization.isSuccess(), ResponseCode.No_Authorization.getTime());
    }

    public static ResponseServer unbound_phone1008(String message) {
        return new ResponseServer(ResponseCode.Unbound_Phone1008.getCode(), message, ResponseCode.Unbound_Phone1008.isSuccess(), ResponseCode.Unbound_Phone1008.getTime());
    }

    public static ResponseServer unbound_phone1009(String message) {
        return new ResponseServer(ResponseCode.Unbound_Phone1009.getCode(), message, ResponseCode.Unbound_Phone1009.isSuccess(), ResponseCode.Unbound_Phone1009.getTime());
    }

}
